import java.applet.Applet;
import java.awt.*;

public class Laufschrift extends Applet implements Runnable {
	Thread m_Marquee = null;
	String m_string = "Default";
	String m_font = "Arial";
	int m_style = Font.BOLD;
	int m_size = 16;
	int m_fps = 30;

	private int m_nOffset;
	private int m_nMax;
	private int m_nMin;

	public void init() {
		int m_size;
		try {
			m_size = Integer.parseInt(getParameter("groesse"));
		} catch (NumberFormatException e1) {
			m_size = 4;
		}
		Font font = new Font(m_font, m_style, m_size);
		setFont(font);

		FontMetrics fm = getFontMetrics(font);
		m_nMin = -fm.stringWidth(m_string);
		m_nMax = size().width;
		m_nOffset = m_nMax;
		try {
			m_string = getParameter("angebot");
		} catch (Exception e) {
			m_string = "Fehler beim Einlesen des String";
		}

	}

	public void paint(Graphics g) {
		int nVertOffset = size().height;
		nVertOffset = ((nVertOffset - m_size) / 2);

		g.drawString(m_string, m_nOffset, nVertOffset + m_size);

		m_nOffset--;
		if (m_nOffset < m_nMin) {
			m_nOffset = m_nMax;
		}
	}

	public void start() {
		m_Marquee = new Thread(this);
		m_Marquee.start();
	}

	public void stop() {
		if (m_Marquee != null) {
			m_Marquee.stop();
			m_Marquee = null;
		}
	}

	public void run() {
		while (true) {
			int nSleepValue = 1000 / m_fps;
			try {
				repaint();
				Thread.sleep(nSleepValue);
			} catch (InterruptedException e) {
				stop();
			}
		}
	}
}
